package  
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	/**
	 * ...
	 * @author Joseph Waters
	 */
	public class Planet extends Sprite
	{
		private var mouseIsDown:int = 0; // Track if mouse has been clicked on the planet being interacted with
		private var pRadius:int = 10; // Radius of the planet
		private var pColor:uint = 0x0000FF; // Color of planet (Blue)
		private var stageX:int = 650;
		private var stageY:int = 480;
		
		private var planetMenus:Menus = new Menus("planet");
		
		public function Planet(stageX:int, stageY:int, nRadius:int) 
		{
			this.addEventListener(MouseEvent.MOUSE_DOWN, downMouse, false, 0, true); // Add a click listener for the planet
			
			// Initialize internal variables
			this.pRadius = nRadius;
			this.pColor = pColor;
			this.stageX = stageX;
			this.stageY = stageY;
			
			this.x = Math.round(Math.random() * this.stageX) + pRadius; // Random x placement of new planet
			this.y = Math.round(Math.random() * this.stageY) + pRadius; // Random y placement of new planet
			
			this.graphics.beginFill(pColor); // Start fill
			this.graphics.drawCircle(0, 0, pRadius); // Draw circle, using radius as defined
			this.graphics.endFill(); // End fill
			
			var dot:Sprite = new Sprite();
			dot.x = 5;
			dot.y = 2;
			dot.graphics.beginFill(0x004411); // Start fill
			dot.graphics.drawCircle(0, 0, 3); // Draw circle, using radius as defined
			dot.graphics.endFill(); // End fill
			this.addChild(dot);
			this.addChild(planetMenus);
		}
		
		public function moveMe(event:MouseEvent):void {
			if (this.mouseIsDown == 1) {
				this.x = stage.mouseX;
				this.y = stage.mouseY;				
			}
		}
		
		private function downMouse(event:MouseEvent):void {
			this.mouseIsDown = 1;
			planetMenus.createMenu(event);
		}
		
		public function upMouse():void {
			this.mouseIsDown = 0;
		}		
	}

}